🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / androidApp / src / google / kotlin / org / meshtastic / app / map / component / NodeClusterMarkers.kt
Displaying Raw • Download
androidApp/src/google/kotlin/org/meshtastic/app/map/component/NodeClusterMarkers.kt c45466a633d6e34df3a0a27c83e169c7eb91e481 (c45466a6) Text, 5.85 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.app.map.component
Tff7b72import T7ee787androidx.compose.runtime.Composable
Tff7b72import T7ee787androidx.compose.runtime.DisposableEffect
Tff7b72import T7ee787androidx.compose.runtime.getValue
Tff7b72import T7ee787androidx.compose.ui.graphics.Color
Tff7b72import T7ee787androidx.compose.ui.platform.LocalView
Tff7b72import T7ee787androidx.lifecycle.Lifecycle
Tff7b72import T7ee787androidx.lifecycle.compose.LocalLifecycleOwner
Tff7b72import T7ee787androidx.lifecycle.compose.currentStateAsState
Tff7b72import T7ee787androidx.lifecycle.findViewTreeLifecycleOwner
Tff7b72import T7ee787androidx.lifecycle.setViewTreeLifecycleOwner
Tff7b72import T7ee787androidx.savedstate.compose.LocalSavedStateRegistryOwner
Tff7b72import T7ee787androidx.savedstate.findViewTreeSavedStateRegistryOwner
Tff7b72import T7ee787androidx.savedstate.setViewTreeSavedStateRegistryOwner
Tff7b72import T7ee787com.google.maps.android.clustering.Cluster
Tff7b72import T7ee787com.google.maps.android.clustering.view.DefaultClusterRenderer
Tff7b72import T7ee787com.google.maps.android.compose.Circle
Tff7b72import T7ee787com.google.maps.android.compose.MapsComposeExperimentalApi
Tff7b72import T7ee787com.google.maps.android.compose.clustering.Clustering
Tff7b72import T7ee787com.google.maps.android.compose.clustering.ClusteringMarkerProperties
Tff7b72import T7ee787org.meshtastic.app.map.model.NodeClusterItem
Tff7b72import T7ee787org.meshtastic.feature.map.BaseMapViewModel
Tf0883e@OptInTb4b4b4(Te6edf3MapsComposeExperimentalApiTff7b72::Te6edf3classTb4b4b4)
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffNestedBlockDepthTa5d6ff"Tb4b4b4)
Tf0883e@Composable
Tff7b72fun Td2a8ffNodeClusterMarkersTb4b4b4(
Te6edf3nodeClusterItemsTb4b4b4: Te6edf3ListTff7b72<Te6edf3NodeClusterItemTff7b72>Tb4b4b4,
Te6edf3mapFilterStateTb4b4b4: Te6edf3BaseMapViewModelTb4b4b4.Te6edf3MapFilterStateTb4b4b4,
Te6edf3navigateToNodeDetailsTb4b4b4: Tb4b4b4(Tffa657IntTb4b4b4) Tff7b72-Tff7b72> Tffa657UnitTb4b4b4,
Te6edf3onClusterClickTb4b4b4: Tb4b4b4(Te6edf3ClusterTff7b72<Te6edf3NodeClusterItemTff7b72>Tb4b4b4) Tff7b72-Tff7b72> Tffa657BooleanTb4b4b4,
Tb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3view Tff7b72= Te6edf3LocalViewTb4b4b4.Te6edf3current
Tff7b72val Te6edf3lifecycleOwner Tff7b72= Te6edf3LocalLifecycleOwnerTb4b4b4.Te6edf3current
Tff7b72val Te6edf3savedStateRegistryOwner Tff7b72= Te6edf3LocalSavedStateRegistryOwnerTb4b4b4.Te6edf3current
Tff7b72val Te6edf3lifecycleState Tff7b72by Te6edf3lifecycleOwnerTb4b4b4.Te6edf3lifecycleTb4b4b4.Te6edf3currentStateAsStateTb4b4b4(Tb4b4b4)
T8b949e// maps-compose renders each non-clustered item to a bitmap through an off-screen ComposeView that
T8b949e// it attaches under the MapView (see ComposeUiClusterRenderer + NoDrawContainerView in
T8b949e// MapComposeViewRender). That ComposeView walks up the view tree for a ViewTreeLifecycleOwner and,
T8b949e// when it finds none, crashes with "Composed into the View which doesn't propagate
T8b949e// ViewTreeLifecycleOwner!" (googlemaps/android-maps-compose#875 / #325) — a FATAL on the map screen.
T8b949e//
T8b949e// Propagate the owners onto this map screen's host view (LocalView.current), which is an ancestor
T8b949e// of the internally-created MapView, so the renderer's ComposeView can resolve them. We deliberately
T8b949e// do NOT touch view.rootView (the activity root): attaching a transient NavEntry lifecycle there is
T8b949e// what caused the node-list popup regression (#5684), which is why #5704 removed the prior, broader
T8b949e// workaround entirely. Scoping to the map host view and restoring the previous owners on dispose
T8b949e// keeps the fix local to the map and leaves Popups/DropdownMenus untouched.
Te6edf3DisposableEffectTb4b4b4(Te6edf3viewTb4b4b4, Te6edf3lifecycleOwnerTb4b4b4, Te6edf3savedStateRegistryOwnerTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3prevLifecycleOwner Tff7b72= Te6edf3viewTb4b4b4.Te6edf3findViewTreeLifecycleOwnerTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3prevSavedStateRegistryOwner Tff7b72= Te6edf3viewTb4b4b4.Te6edf3findViewTreeSavedStateRegistryOwnerTb4b4b4(Tb4b4b4)
Te6edf3viewTb4b4b4.Te6edf3setViewTreeLifecycleOwnerTb4b4b4(Te6edf3lifecycleOwnerTb4b4b4)
Te6edf3viewTb4b4b4.Te6edf3setViewTreeSavedStateRegistryOwnerTb4b4b4(Te6edf3savedStateRegistryOwnerTb4b4b4)
Te6edf3onDispose Tb4b4b4{
Te6edf3viewTb4b4b4.Te6edf3setViewTreeLifecycleOwnerTb4b4b4(Te6edf3prevLifecycleOwnerTb4b4b4)
Te6edf3viewTb4b4b4.Te6edf3setViewTreeSavedStateRegistryOwnerTb4b4b4(Te6edf3prevSavedStateRegistryOwnerTb4b4b4)
Tb4b4b4}
Tb4b4b4}
T8b949e// The cluster renderer drives marker rendering from an async Handler (DefaultClusterRenderer's
T8b949e// MarkerModifier), which can fire after this screen has stopped and the internal ComposeView is
T8b949e// detached — at which point no owner is reachable regardless of the above. Skip rendering once the
T8b949e// lifecycle is no longer at least STARTED to close most of that race.
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3lifecycleStateTb4b4b4.Te6edf3isAtLeastTb4b4b4(Te6edf3LifecycleTb4b4b4.Te6edf3StateTb4b4b4.Te6edf3STARTEDTb4b4b4)Tb4b4b4) Tff7b72return
Te6edf3ClusteringTb4b4b4(
Te6edf3items Tff7b72= Te6edf3nodeClusterItemsTb4b4b4,
Te6edf3onClusterClick Tff7b72= Te6edf3onClusterClickTb4b4b4,
Te6edf3onClusterItemInfoWindowClick Tff7b72= Tb4b4b4{ Te6edf3item Tff7b72-Tff7b72>
Te6edf3navigateToNodeDetailsTb4b4b4(Te6edf3itemTb4b4b4.Te6edf3nodeTb4b4b4.Te6edf3numTb4b4b4)
Tff7b72false
Tb4b4b4}Tb4b4b4,
Te6edf3clusterItemContent Tff7b72= Tb4b4b4{ Te6edf3clusterItem Tff7b72-Tff7b72> Te6edf3PulsingNodeChipTb4b4b4(Te6edf3node Tff7b72= Te6edf3clusterItemTb4b4b4.Te6edf3nodeTb4b4b4) Tb4b4b4}Tb4b4b4,
Te6edf3onClusterManager Tff7b72= Tb4b4b4{ Te6edf3clusterManager Tff7b72-Tff7b72>
Tb4b4b4(Te6edf3clusterManagerTb4b4b4.Te6edf3renderer Tff7b72as Te6edf3DefaultClusterRendererTb4b4b4)Tb4b4b4.Te6edf3minClusterSize Tff7b72= T79c0ff1T79c0ff0
Tb4b4b4}Tb4b4b4,
Te6edf3clusterItemDecoration Tff7b72= Tb4b4b4{ Te6edf3clusterItem Tff7b72-Tff7b72>
Tff7b72if Tb4b4b4(Te6edf3mapFilterStateTb4b4b4.Te6edf3showPrecisionCircleTb4b4b4) Tb4b4b4{
Te6edf3clusterItemTb4b4b4.Te6edf3getPrecisionMetersTb4b4b4(Tb4b4b4)Tff7b72?.Te6edf3let Tb4b4b4{ Te6edf3precisionMeters Tff7b72-Tff7b72>
Tff7b72if Tb4b4b4(Te6edf3precisionMeters Tff7b72> T79c0ff0Tb4b4b4) Tb4b4b4{
Te6edf3CircleTb4b4b4(
Te6edf3center Tff7b72= Te6edf3clusterItemTb4b4b4.Te6edf3positionTb4b4b4,
Te6edf3radius Tff7b72= Te6edf3precisionMetersTb4b4b4,
Te6edf3fillColor Tff7b72= Te6edf3ColorTb4b4b4(Te6edf3clusterItemTb4b4b4.Te6edf3nodeTb4b4b4.Te6edf3colorsTb4b4b4.Te6edf3secondTb4b4b4)Tb4b4b4.Te6edf3copyTb4b4b4(Te6edf3alpha Tff7b72= T79c0ff0.2fTb4b4b4)Tb4b4b4,
Te6edf3strokeColor Tff7b72= Te6edf3ColorTb4b4b4(Te6edf3clusterItemTb4b4b4.Te6edf3nodeTb4b4b4.Te6edf3colorsTb4b4b4.Te6edf3secondTb4b4b4)Tb4b4b4,
Te6edf3strokeWidth Tff7b72= T79c0ff2fTb4b4b4,
Te6edf3zIndex Tff7b72= T79c0ff0fTb4b4b4,
Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
T8b949e// Use the item's own priority-based zIndex (5f for My Node/Favorites, 4f for others)
Te6edf3ClusteringMarkerPropertiesTb4b4b4(Te6edf3zIndex Tff7b72= Te6edf3clusterItemTb4b4b4.Te6edf3getZIndexTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4}Tb4b4b4,
Tb4b4b4)
Tb4b4b4}
Served by rngit 1.5.3 - Generated in 0.04s